package com.logica.tutorial.web;

import java.lang.reflect.Type;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.logica.tutorial.dto.PersonDTO;

public class PersonSerializer implements JsonSerializer<PersonDTO>{

	@Override
	public JsonElement serialize(PersonDTO person, Type arg1,
			JsonSerializationContext arg2) {
		JsonObject obj = new JsonObject();
		obj.addProperty("id", person.getId());
		obj.addProperty("sex", person.getSex().toString());
		obj.addProperty("firstName", person.getFirstName());
		obj.addProperty("lastName", person.getLastName());
		obj.addProperty("street", person.getAddress().getStreet());
		obj.addProperty("houseNr", person.getAddress().getHouseNr());
		obj.addProperty("city", person.getAddress().getCity());
		obj.addProperty("zipCode", person.getAddress().getZipCode());
		return obj;
	}

}
